834B - The Festive Evening - CodeForces Solution


data structures implementation *1100

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <map>
using namespace std;

int main() {
	// your code goes here
	long long int n;
	int k;
	string s;
	cin>>n>>k>>s;
	map<int,char>mp,mp2;
	for(int i=65;i<=90;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(s[j]==(char)i)
			{
				mp[j]=(char)i;
				break;
			}
		}
	}
	for(int i=65;i<=90;i++)
	{
		for(int j=n-1;j>=0;j--)
		{
			if(s[j]==(char)i)
			{
				mp2[j]=(char)i;
				break;
			}
		}
	}
	map<int,char>::iterator it,it2;
	long long int check=0,flag=0;
	for(int i=0;i<n;i++)
	{
		it=mp.find(i);
		if(it!=mp.end())
		check++;
		if(check>k){
		cout<<"YES"<<endl;
		flag=1;
		break;}
		it2=mp2.find(i);
		if(it2!=mp2.end())
		check--;
	}
	if(flag==0)
	cout<<"NO"<<endl;
	return 0;
}


Comments

Submit
0 Comments
More Questions

1038A - Equality
1061A - Coins
1676E - Eating Queries
1447A - Add Candies
1721D - Maximum AND
363C - Fixing Typos
1401A - Distance and Axis
658A - Bear and Reverse Radewoosh
1721E - Prefix Function Queries
977E - Cyclic Components
1140D - Minimum Triangulation
75C - Modified GCD
1722A - Spell Check
1722B - Colourblindness
1722D - Line
1722C - Word Game
1722G - Even-Odd XOR
552E - Vanya and Brackets
933A - A Twisty Movement
1722F - L-shapes
1196B - Odd Sum Segments
1325D - Ehab the Xorcist
552B - Vanya and Books
1722E - Counting Rectangles
168A - Wizards and Demonstration
168B - Wizards and Minimal Spell
7A - Kalevitch and Chess
912B - New Year's Eve
1537C - Challenging Cliffs
879B - Table Tennis